﻿Public Class Sach_DAL
    Dim cn As New ConnectDB()
    Public Function Sach() As DataTable
        Return cn.loadData("load_sach")
    End Function
    Public Function loadSachUserPage() As DataTable
        Return cn.loadData("load_sachtrangchu")
    End Function
    Public Function Sach_ChiTiet(ByVal p As Sach_DTO) As DataTable
        Dim Nparameter As Integer = 1
        Dim name As String() = New String(Nparameter - 1) {}
        Dim value As Object() = New Object(Nparameter - 1) {}
        name(0) = "@id_sach"
        value(0) = p._idsach
        Return cn.loadData("load_sachchitiet", name, value, Nparameter)
    End Function
    Public Function ThemSach(ByVal p As Sach_DTO) As Integer
        Dim Nparameter As Integer = 13
        Dim name As String() = New String(Nparameter - 1) {}
        Dim value As Object() = New Object(Nparameter - 1) {}


        name(0) = "@id"
        value(0) = ""

        name(1) = "@id_sach"
        value(1) = p._idsach

        name(2) = "@tensach"
        value(2) = p._ten

        name(3) = "@tendm"
        value(3) = p._danhmuc

        name(4) = "@hinh"
        value(4) = p._hinhanh

        name(5) = "@chitiet"
        value(5) = p._chitiet

        name(6) = "@tacgia"
        value(6) = p._tacgia

        name(7) = "@nxb"
        value(7) = p._nxb

        name(8) = "@phanloai"
        value(8) = p._phanloai

        name(9) = "@ngaynhap"
        value(9) = ""

        name(10) = "ke"
        value(10) = p._ke

        name(11) = "hang"
        value(11) = p._hang

        name(12) = "soluong"
        value(12) = p._soluong

        Return cn.updateData("themsach", name, value, Nparameter)

    End Function

    Public Function CapNhapSach(ByVal p As Sach_DTO) As Integer
        Dim Nparameter As Integer = 9
        Dim name As String() = New String(Nparameter - 1) {}
        Dim value As Object() = New Object(Nparameter - 1) {}
        name(0) = "@id_sach"
        value(0) = p._idsach

        name(1) = "tensach"
        value(1) = p._ten

        name(2) = "tendm"
        value(2) = p._danhmuc

        name(3) = "ngaynhap"
        value(3) = p._ngaynhap

        name(4) = "tacgia"
        value(4) = p._tacgia

        name(5) = "nxb"
        value(5) = p._nxb

        name(6) = "phanloai"
        value(6) = p._phanloai

        name(7) = "hinh"
        value(7) = p.hinhanh

        name(8) = "chitiet"
        value(8) = p.chitiet

        Return cn.updateData("capnhatsach", name, value, Nparameter)
    End Function

    Public Function XoaSach(ByVal p As Sach_DTO) As Integer
        Dim Nparameter As Integer = 1
        Dim name As String() = New String(Nparameter - 1) {}
        Dim value As Object() = New Object(Nparameter - 1) {}

        name(0) = "id_sach"
        value(0) = p._idsach

        Return cn.updateData("xoasach", name, value, Nparameter)
    End Function

    Public Function Load_VitriKe() As DataTable
        Return cn.loadData("load_ke")
    End Function
    Public Function Load_VitriHang(ByVal p As Sach_DTO) As DataTable
        Dim Nparameter As Integer = 1
        Dim name As String() = New String(Nparameter - 1) {}
        Dim value As Object() = New Object(Nparameter - 1) {}

        name(0) = "ke"
        value(0) = p._ke

        Return cn.loadData("load_hang", name, value, Nparameter)
    End Function
    Public Function Them_VitriKe(ByVal p As Sach_DTO) As DataTable
        Dim Nparameter As Integer = 1
        Dim name As String() = New String(Nparameter - 1) {}
        Dim value As Object() = New Object(Nparameter - 1) {}

        name(0) = "ke"
        value(0) = p._ke

        Return cn.loadData("themke", name, value, Nparameter)
    End Function

    Public Function load_sachtheovitri(ByVal p As Sach_DTO) As DataTable
        Dim Nparameter As Integer = 2
        Dim name As String() = New String(Nparameter - 1) {}
        Dim value As Object() = New Object(Nparameter - 1) {}

        name(0) = "ke"
        value(0) = p._ke

        name(1) = "hang"
        value(1) = p._hang

        Return cn.loadData("loadsachtheovitri", name, value, Nparameter)
    End Function
    Public Function load_sachtheovitrimaten(ByVal p As Sach_DTO) As DataTable
        Dim Nparameter As Integer = 1
        Dim name As String() = New String(Nparameter - 1) {}
        Dim value As Object() = New Object(Nparameter - 1) {}

        name(0) = "text"
        value(0) = p._text
        Return cn.loadData("loadinfosachtheomaten", name, value, Nparameter)
    End Function
    Public Function CapNhapViTri(ByVal p As Sach_DTO)
        Dim Nparameter As Integer = 3
        Dim name As String() = New String(Nparameter - 1) {}
        Dim value As Object() = New Object(Nparameter - 1) {}

        name(0) = "id_sach"
        value(0) = p._idsach

        name(1) = "ke"
        value(1) = p._ke

        name(2) = "hang"
        value(2) = p._hang
        Return cn.loadData("capnhatvitri", name, value, Nparameter)
    End Function
    Public Function xoaKe(ByVal p As Sach_DTO)
        Dim Nparameter As Integer = 1
        Dim name As String() = New String(Nparameter - 1) {}
        Dim value As Object() = New Object(Nparameter - 1) {}

        name(0) = "ke"
        value(0) = p._ke

        Return cn.loadData("xoavitri", name, value, Nparameter)
    End Function
    Public Function thongkeSachTheoDM() As DataTable
        Return cn.loadData("thongkesach_danhmuc")
    End Function
    Public Function thongkeSachTheoPL() As DataTable
        Return cn.loadData("thongkesach_phanloai")
    End Function
    Public Function thongkeSachTheoNXB() As DataTable
        Return cn.loadData("thongkesach_nxb")
    End Function
    Public Function timkiemSach(ByVal p As Sach_DTO)
        Dim Nparameter As Integer = 1
        Dim name As String() = New String(Nparameter - 1) {}
        Dim value As Object() = New Object(Nparameter - 1) {}

        name(0) = "text"
        value(0) = p._text

        Return cn.loadData("timkiem", name, value, Nparameter)
    End Function
    Public Function loadSachTheoDM(ByVal p As Sach_DTO)
        Dim Nparameter As Integer = 1
        Dim name As String() = New String(Nparameter - 1) {}
        Dim value As Object() = New Object(Nparameter - 1) {}

        name(0) = "tendm"
        value(0) = p._danhmuc

        Return cn.loadData("load_sachtheodm", name, value, Nparameter)
    End Function
End Class
